package com.ext.aic.components;

import android.content.Context;
import android.util.AttributeSet;

import com.ext.aic.events.OnSelectionChangeListener;
import com.eyinfo.android_pure_utils.utils.ObjectJudge;
import com.onegravity.rteditor.RTEditText;

import java.util.ArrayList;
import java.util.List;

public class ObservableRTEditText extends RTEditText {
    public ObservableRTEditText(Context context) {
        super(context);
    }

    public ObservableRTEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private List<OnSelectionChangeListener> listeners = new ArrayList<>();

    public void addOnSelectionChangeListener(OnSelectionChangeListener listener) {
        listeners.add(listener);
    }

    @Override
    protected void onSelectionChanged(int start, int end) {
        super.onSelectionChanged(start, end);
        if (!ObjectJudge.isNullOrEmpty(listeners)) {
            for (OnSelectionChangeListener listener : listeners) {
                listener.onSelectionChanged(start, end);
            }
        }
    }
}
